<template>
  <footer class="footer">
    <span class="todo-count">剩余<strong>数量值</strong>{{ leftCount }}</span>
    <ul class="filters">
      <li>
        <a
          :class="{ selected: liang === 'all' }"
          @click="change('all')"
          href="javascript:;"
          >全部</a
        >
      </li>
      <li>
        <a
          :class="{ selected: liang === 'active' }"
          @click="change('active')"
          href="javascript:;"
          >未完成</a
        >
      </li>
      <li>
        <a
          :class="{ selected: liang === 'complete' }"
          @click="change('complete')"
          href="javascript:;"
          >已完成</a
        >
      </li>
    </ul>
    <button class="clear-completed" @click="clear" v-show="isShow">
      清除已完成
    </button>
  </footer>
</template>

<script>
export default {
  data() {
    return {
      liang: "all",
    };
  },
  props: ["arr"],
  computed: {
    // 未完成数量
    leftCount() {
      return this.arr.filter((item) => !item.isDone).length;
    },
    // 显示与隐藏清除已完成
    isShow() {
      return this.arr.some((item) => item.isDone);
    },
  },
  methods: {
    // 清除x已完成
    clear() {
      this.$emit("clear");
    },
    // 高亮
    change(val) {
      // console.log(val);
      this.liang = val;
      this.$emit("change", val);
    },
  },
};
</script>
